<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绘制图片</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>

<body>
    <img src="./img/1.png" alt="">
    <canvas id="tutorial" width="400" height="300">你的浏览器不支持 canvas，请升级你的浏览器。</canvas>
    <script>
        function draw() {
            var canvas = document.getElementById('tutorial');
            if (!canvas.getContext) return;
            var ctx = canvas.getContext("2d");
            var img = document.querySelector("img");
            ctx.drawImage(img, 0, 0,400,200);
        }
        document.querySelector("img").onclick = function () {
            draw();
        }
    </script>
</body>

</html>